home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / atigupro.asm < prev    next >
Assembly Source File  |  1993-09-16  |  12KB  |  384 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file ATIGUPRO.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ; Copyright (C) 1993 Clint Wolff, 4519 Starboard Ct, Boulder, CO 80301
  7. ;
  8. ; This file is distributed under the terms listed in the document
  9. ; "copying.dj", available from DJ Delorie at the address above.
  10. ; A copy of "copying.dj" should accompany this file; if not, a copy
  11. ; should be available from where this file was obtained.  This file
  12. ; may not be distributed without a verbatim copy of "copying.dj".
  13. ;
  14. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. ;--------------------------------------------------------------------------
  17.  
  18. _TEXT    segment byte public 'CODE'
  19. _TEXT    ends
  20. DGROUP  group    _TEXT,_DATA,_BSS
  21.     assume  cs:_TEXT,ds:DGROUP
  22. _DATA    segment word public 'DATA'
  23. d@    label    byte
  24. d@w    label    word
  25. _DATA    ends
  26. _BSS    segment word public 'BSS'
  27. b@    label    byte
  28. b@w    label    word
  29. _BSS    ends
  30. _TEXT    segment byte public 'CODE'
  31.     assume  cs:_TEXT,ds:DGROUP
  32.  
  33. include grdriver.inc
  34.  
  35. ;--------------------------------------------------------------------------
  36. ; DRIVER HEADER
  37. ;  The following entries MUST match the structure and constant
  38. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  39. ;  The mode word should contain the following bitfields:
  40. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  41. ;     - the adapter type field should be specified
  42. ;     - the memory size field should be specified
  43. ;     - the paging mode field should be specified
  44. ;  The mode set routine will OR in the plane bitfield as it will
  45. ;  change when different color number modes are requested.
  46. ;--------------------------------------------------------------------------
  47.  
  48.     dw    offset mode_set_routine
  49.     dw    offset paging_routine
  50. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_RW_64K
  51. ;
  52. ; The 'def_xx' fields are filled in by go32 from the corresponding
  53. ; fields of the 'GO32' environment variable
  54. ;
  55. def_tw  dw    80        ; text width
  56. def_th  dw    25        ; text height
  57. def_gw  dw    640        ; graphics width
  58. def_gh  dw    480        ; graphics height
  59. def_nc  dw    16        ; graphics colors
  60.     dw    offset driver_init_routine
  61.     dw    offset text_mode_table
  62.     dw    offset graphics_mode_table
  63.  
  64. ;
  65. ; Biggest text and graphics sizes
  66. ;
  67. Max_TW  equ    132
  68. Max_TH  equ    44
  69. Max_GWn equ    1024        ; non interlaced!!!
  70. Max_GHn equ    768
  71. Max_GW  equ    1024        ; may be interlaced
  72. Max_GH  equ    768
  73.  
  74.  
  75. ;--------------------------------------------------------------------------
  76. ; TABLE OF SUPPORTED TEXT MODES
  77. ;    - keep sorted by size
  78. ;    - end with an all 0 entry
  79. ;    - BIOS field = 0xff disables it
  80. ;    - fields:
  81. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  82. ;--------------------------------------------------------------------------
  83. text_mode_table        label word
  84.     dw    80,    25,    2,    007h +  00000h
  85.     dw    40,    25,    16,    001h +  00000h
  86.     dw    80,    25,    16,    003h +  00000h
  87.     dw    132,    25,    16,    023h +  00000h
  88.     dw    0,    0,    0,    000h +  00000h
  89.  
  90. ;--------------------------------------------------------------------------
  91. ; TABLE OF SUPPORTED GRAPHICS MODES
  92. ;    - keep sorted first by colors then by size
  93. ;    - end with an all 0 entry
  94. ;    - BIOS field = 0xff disables it
  95. ;    - fields:
  96. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  97. ;--------------------------------------------------------------------------
  98. graphics_mode_table    label word
  99.     dw    320,    200,    16,    00dh +  00000h
  100.     dw    640,    200,    16,    00eh +  00000h
  101.     dw    640,    350,    16,    010h +  00000h
  102.     dw    640,    480,    16,    012h +  00000h
  103.     dw    800,    600,    16,    054h +  00000h
  104.     dw    1024,    768,    16,    055h +  00000h
  105.     dw    320,    200,    256,    013h +  00000h
  106.     dw    640,    480,    256,    062h +  00000h
  107.     dw    800,    600,    256,    063h +  00000h
  108.     dw    1024,    768,    256,    064h +  00000h
  109.     dw    0,    0,    0,    000h +  00000h
  110.  
  111. ;--------------------------------------------------------------------------
  112. ; TABLE OF SPECIAL SETUP PROCEDURES
  113. ;  You may need such procedures for:
  114. ;     -- reloading fonts on standard EGA or VGA for
  115. ;     higher resolution text modes
  116. ;     -- enable HiColor mode of some Super VGAs
  117. ;     -- Handle the parameter passing conventions of the VESA BIOS
  118. ;     -- put VGA into 256 color plane mode ("MODE X")
  119. ;     -- etc...
  120. ;  There should be one entry in the table for every non-zero
  121. ;  'setup_procedure_index' in the text and graphics mode tables.
  122. ;  The first entry in the table belongs to index 100h, and so on.
  123. ;  The special setup procedure is invoked via a near call.
  124. ;
  125. ;  Entry: DI=address of the mode record from the text or graphics
  126. ;      table to set up.
  127. ;
  128. ;  Exit:  Adapter configured
  129. ;      BX=driver mode word as it should be returned by the mode set
  130. ;         routine. Typically it involves picking up the mode word
  131. ;         from the header and OR-ing in the appropriate bitplane mode
  132. ;         bitfield. (This is not needed for text modes)
  133. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  134. ;
  135. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  136. ;--------------------------------------------------------------------------
  137. special_setup_table    label word
  138.     dw    offset  VGA_44row_mode_set
  139.  
  140. ;
  141. ; Routine to set up VGA 44 row mode
  142. ; interface is described above
  143. ;
  144. VGA_44row_mode_set    proc    near
  145.     mov    ax,03h            ; set 80x25 mode
  146.     int    10h
  147.     xor    bx,bx
  148.     mov    ax,1112h        ; load 8x8 font
  149.     int    10h
  150.     ret
  151. VGA_44row_mode_set    endp
  152.  
  153. ;--------------------------------------------------------------------------
  154. ; DRIVER INIT ROUTINE
  155. ;  called once after the driver is loaded
  156. ;  may do one or more of the followings:
  157. ;    - check for proper board type
  158. ;    - check amount of RAM on board, and:
  159. ;    -- update word in header to reflect correct amount
  160. ;    -- disable modes in the tables for which there is not enough RAM
  161. ;    - check for special equipment (HiColor DAC, etc...)
  162. ;
  163. ;  Entry: nothing
  164. ;
  165. ;  Exit:  AX=status:
  166. ;       non-zero: OK,
  167. ;       0: something went wrong (e.g. wrong adapter, etc..)
  168. ;      BX,CX,DX may be trashed
  169. ;
  170. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  171. ;--------------------------------------------------------------------------
  172. driver_init_routine    proc    far
  173.     mov    ax,1
  174.     ret
  175. driver_init_routine    endp
  176.  
  177.  
  178. ;--------------------------------------------------------------------------
  179. ; MODE SET ROUTINE
  180. ;  sets up a text or graphics mode as close as possible to the one
  181. ;  reguested by the user with regard to number of colors and size.
  182. ;
  183. ;  Entry: AX=mode selection
  184. ;     0 = 80x25 text
  185. ;     1 = default text
  186. ;     2 = text CX cols by DX rows
  187. ;     3 = biggest text
  188. ;     4 = 320x200 graphics
  189. ;     5 = default graphics
  190. ;     6 = graphics CX width by DX height
  191. ;     7 = biggest non-interlaced graphics
  192. ;     8 = biggest graphics
  193. ;     9 = graphics BX colors, CX width by DX height
  194. ;
  195. ;  Exit: BX=driver mode flag
  196. ;     CX=width (in pixels or characters)
  197. ;     DX=height
  198. ;
  199. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  200. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  201. ;     MUCH TABLE DRIVEN
  202. ;--------------------------------------------------------------------------
  203. mode_set_routine    proc    far
  204.     push    ds
  205.     push    di
  206.     push    si
  207.     mov    si,cs
  208.     mov    ds,si
  209.     cmp    ax,9
  210.     jbe    DoIt
  211.     jmp    Exit
  212. DoIt:    add    ax,ax
  213.     mov    si,ax
  214.     jmp    WORD PTR mode_set_table[si]
  215. mode_set_table  label    word
  216.     dw    offset mode_0
  217.     dw    offset mode_1
  218.     dw    offset mode_2
  219.     dw    offset mode_3
  220.     dw    offset mode_4
  221.     dw    offset mode_5
  222.     dw    offset mode_6
  223.     dw    offset mode_7
  224.     dw    offset mode_8
  225.     dw    offset mode_9
  226. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  227.     mov    bx,def_nc
  228.     mov    cx,80
  229.     mov    dx,25
  230.     jmp    Lookup
  231. mode_1: mov    si,offset text_mode_table    ; default text
  232.     mov    bx,def_nc
  233.     mov    cx,def_tw
  234.     mov    dx,def_th
  235.     jmp    Lookup
  236. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  237.     mov    bx,def_nc
  238.     jmp    Lookup
  239. mode_3: mov    si,offset text_mode_table    ; biggest text
  240.     mov    bx,def_nc
  241.     mov    cx,Max_TW
  242.     mov    dx,Max_TH
  243.     jmp    Lookup
  244. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  245.     mov    bx,def_nc
  246.     mov    cx,320
  247.     mov    dx,200
  248.     jmp    Lookup
  249. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  250.     mov    bx,def_nc
  251.     mov    cx,def_gw
  252.     mov    dx,def_gh
  253.     jmp    Lookup
  254. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  255.     mov    bx,def_nc
  256.     jmp    Lookup
  257. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  258.     mov    bx,def_nc
  259.     mov    cx,Max_GWn
  260.     mov    dx,Max_GHn
  261.     jmp    Lookup
  262. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  263.     mov    bx,def_nc
  264.     mov    cx,Max_GW
  265.     mov    dx,Max_GH
  266.     jmp    Lookup
  267. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  268. ;
  269. ; At this point:
  270. ;   SI points to the table to search (text or graphics)
  271. ;   BX has colors
  272. ;   CX has width
  273. ;   DX has height
  274. ;
  275. Lookup: xor    ax,ax                ; last color number seen
  276. Find_C: cmp    [si+4],ax            ; last color number == this?
  277.     je    Same_C
  278.     jb    Prev_C                ; end of table -- use last color
  279.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  280.     je    Prev_C                ; not -- use last color
  281.     mov    ax,[si+4]            ; record color number
  282.     mov    di,si                ; start of entries w/ this color
  283.     cmp    ax,bx                ; enough colors ?
  284.     jae    Find_S
  285. Same_C: add    si,8
  286.     jmp    Find_C
  287. Prev_C: or    ax,ax                ; found any color at all?
  288.     je    Exit
  289. ;
  290. ; At this point:
  291. ;   DI points into the table to the first entry with the desired color
  292. ;      number (either it has enough colors or it is the highest color
  293. ;      number supported by the driver). Additionally, at least the
  294. ;      first (= smallest size) entry for this color is valid (has a
  295. ;      valid BIOS number).
  296. ;   AX has the color number adjusted for the driver
  297. ;   CX has width
  298. ;   DX has height
  299. ;
  300. Find_S: cmp    [di+4],ax            ; still the same color #?
  301.     jne    Prev_S
  302.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  303.     je    Prev_S
  304.     cmp    [di],cx
  305.     jb    Next_S
  306.     cmp    [di+2],dx
  307.     jae    GotIt
  308. Next_S: add    di,8
  309.     jmp    Find_S
  310. Prev_S: sub    di,8
  311. ;
  312. ; At this point:
  313. ;   DI points to the table entry we want to set up
  314. ;
  315. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  316.     or    ah,ah                ; special ?
  317.     je    doBIOS
  318.     mov    al,ah
  319.     xor    ah,ah
  320.     dec    ax
  321.     add    ax,ax
  322.     mov    si,ax
  323.     call    WORD PTR special_setup_table[si]
  324.     jmp    RetVal
  325. doBIOS: int    10h
  326.     mov    bx,GRD_1_PLANE
  327.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  328.     je    doFLAG
  329.     mov    bx,GRD_4_PLANES
  330.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  331.     je    doFLAG
  332.     mov    bx,GRD_8_PLANES
  333.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  334.     je    doFLAG
  335.     mov    bx,GRD_16_PLANES
  336.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  337.     je    doFLAG
  338.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  339. doFLAG: or    bx,mode_W
  340. RetVal: mov    cx,[di]
  341.     mov    dx,[di+2]
  342. Exit:    pop    si
  343.     pop    di
  344.     pop    ds
  345.     ret
  346. mode_set_routine    endp
  347.  
  348.  
  349. ;--------------------------------------------------------------------------
  350. ; PAGING ROUTINE
  351. ;
  352. ;  Entry: AH=read page
  353. ;      AL=write page
  354. ;
  355. ;  Exit: VGA configured.
  356. ;     AX,BX,CX,DX,SI,DI may be trashed
  357. ;
  358. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  359. ;     This code must be relocatable and may not reference any data!
  360. ;--------------------------------------------------------------------------
  361.     assume  ds:nothing, es:nothing
  362.  
  363. paging_routine  proc    far
  364.     and    ah,0fh        ; Read-plane on bits 7-6-5
  365.     ror    ah,1
  366.     ror    ah,1
  367.     ror    ah,1
  368.  
  369.     and    al,0fh        ; Write-plane on bits 3-2-1
  370.     shl    al,1
  371.  
  372.     or    ah,al        ; Combine Read and Write plane
  373.  
  374.     mov    dx,01ceh    ; ATI register
  375.     mov    al,0b2h        ; plane select
  376.     out    dx,ax
  377.     ret
  378. paging_routine  endp
  379.  
  380. _TEXT    ends
  381.  
  382.     end
  383.  
  384.